package drds.binlog.database_driver.packets;

import drds.binlog.common.Authors;
import drds.common.Author;

import java.io.IOException;

/**
 * Top Abstraction for network packet.<br>
 * it exposes 2 behaviors for sub-class implementation which will be used to
 * marshal data into bytes before sending and to un-marshal data from data after
 * receiving.<br>
 */
@Author(name = Authors.LI_YANG)
public interface Packet
{

    /**
     * un-marshal raw bytes into {@link Packet} state for application usage.<br>
     *
     * @param bytes, the raw byte data received from networking
     */
    void fromBytes(byte[] bytes) throws IOException;

    /**
     * marshal the {@link Packet} state into raw bytes for sending out to
     * network.<br>
     *
     * @return the bytes that's collected from {@link Packet} state
     */
    byte[] toBytes() throws IOException;
}
